using UnityEditor;

namespace CGF
{
    [CustomEditor(typeof(CSlider))]
    public class CSliderEditor : Editor
    {
        SerializedObject obj;
        SerializedProperty[] propertys;
        CSlider slider;

        void OnEnable()
        {
            slider = target as CSlider;
            obj = new SerializedObject(target);
            propertys = new SerializedProperty[] {
                obj.FindProperty("fill"),
                obj.FindProperty("head"),
                obj.FindProperty("left"),
                obj.FindProperty("right"),
                obj.FindProperty("ctrlHeadAlpha"),
                obj.FindProperty("leftAlpha0"),
                obj.FindProperty("leftAlpha1"),
                obj.FindProperty("rightAlpha1"),
                obj.FindProperty("rightAlpha0"),
            };
        }

        public override void OnInspectorGUI()
        {
            EditorGUI.BeginChangeCheck();
            for (int i = 0; i < propertys.Length; i++)
            {
                EditorGUILayout.PropertyField(propertys[i], true);
                if (i == 0)
                {
                    slider.value = EditorGUILayout.Slider("Value", slider.value, 0, 1);
                }
            }
            if (EditorGUI.EndChangeCheck())
            {
                obj.ApplyModifiedProperties();
                EditorUtility.SetDirty(target);
            }
        }
    }
}